#include <stdio.h>
#include <stdlib.h>
#include "box.h"


box boxNew(size_t size){
    box b={0};
    if ((b.ptr=malloc(size)))
    {
        b.cap=size;
    }
    return b;
}

box boxRenew(box b,size_t new_size){
    void *tmp=realloc(b.ptr,new_size);
    if (tmp)
    {
        b.ptr=tmp;
        b.cap=new_size;
    }
    return b;
}

void boxFree(box b){
    free(b.ptr);
    b.ptr=NULL;
    b.cap=0;
}

size_t boxSizeof(box b){
    return b.cap;
}